package org.gw.building.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.gw.building.model.base.*;
import org.gw.ylc.base.model.Teacher;
import org.gw.ylc.base.model.Xl;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.util.Date;

/**
 * @author qianwx
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "T_TQTJ_TYXXB")
@AllArgsConstructor
@Builder
public class Tyxxb {

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid")
    private String id;

    private String yx;

    @OneToOne
    @JoinColumn(name = "zbmc")
    private Bm zbmc;

    private String xh;

    private String xm;

    @ManyToOne
    @JoinColumn(name = "xb")
    private Xb xb;

    private Date csrq;

    @OneToOne
    @JoinColumn(name = "mz")
    private Mz mz;

    @OneToOne
    @JoinColumn(name = "zzmm")
    private Zzmm zzmm;

    @OneToOne
    @JoinColumn(name = "whcd")
    private Xl whcd;

    private boolean tgb;

    private boolean zbsj;

    private boolean zbwy;

    private String tnzw;

    private String bz;

    private Date rtrq;

    private Date sqrdrq;

    private Date tntyrq;

    private Date fzwybdyrq;

    private Date zzrq;

    @OneToOne
    @JoinColumn(name = "lx")
    private Rylx lx;

    private boolean scbz;

    @OneToOne
    @JoinColumn(name = "sjly")
    private Sjly sjly;

    @Transient
    public int getNl(){
        FastDateFormat fdf = FastDateFormat.getInstance("yyyy");
        String birthYear = fdf.format(csrq);
        String nowYear = fdf.format(new Date());
        if(StringUtils.isBlank(birthYear)){
            return 0;
        }
        return Integer.valueOf(nowYear) - Integer.valueOf(birthYear);
    }

    @Transient
    private Teacher teacher;

    @Transient
    public String getJztgb(){
        return tgb ? "专职" : "兼职";
    }
}
